package com.example.my_self_view.practice1

import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.animation.DecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import com.example.my_self_view.databinding.ActivityTest1Binding

class Test1Activity: AppCompatActivity() {

    private lateinit var mBinding: ActivityTest1Binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityTest1Binding.inflate(layoutInflater)
        setContentView(mBinding.root)

        startAnimator()
        mBinding.myProgress.setOnClickListener {
            startAnimator()
        }
    }

    private fun startAnimator() {
        val animator = ObjectAnimator.ofFloat(0f, 100f)
        animator.duration = 2000L
        animator.interpolator = DecelerateInterpolator()
        animator.addUpdateListener {
            val currentProgress = it.animatedValue as Float
            mBinding.myProgress.setCurrentProgress(currentProgress.toInt())
        }
        animator.start()
    }
}